"""
循环语句有 for 和 while

在 Python 中没有 do..while 循环
"""

print("==========while循环==========")
# 以下实例使用了 while 来计算 1 到 10 的总和：
n = 10
sum = 0
count = 1

while count <= n:
    count += 1
    sum += count

print(sum)

print("==========while else循环==========")

age = 18
while age <= 20:
    print('小于20岁,现在：', age)
    age += 1
else:
    print('大于20岁')

print("==========for循环==========")

list1 = ['JD', 'Tianmao', 'pdd']
for x in list1:
    print(x)

print("==========for break循环==========")

list1 = ['JD', 'Tianmao', 'pdd']
for x in list1:
    if x == 'Tianmao':
        print("欢迎光临天猫商城")
        break
    print('已遍历：', x)
else:
    print('空集合，无法遍历')
print('结束啦')

# range() 用于生成一个整数序列。它可以接受1个、2个或3个参数，并返回一个可迭代的整数对象
print("==========for range循环==========")
for x in range(4):
    print(x, end=',')

print()

for x in range(0, 10, 2):
    print(x, end=',')
print()

print("==========for循环 break continue==========")
n = 4
for x in range(5):
    if x < n:
        print(f'当前x等于{x},continue跳出当前走下一个')
        continue
    elif x == 4:
        print(f'当前x等于{x},break终止循环')
        break
print('循环结束')

print("==========while循环 break continue==========")
n = 10
while n > 0:
    print('break-->n:', n)
    n -= 1
    if n == 5:
        break

n = 10
while n > 0:
    n -= 1
    if n == 5:
        continue
    print('continue-->n:', n)

print("==========for循环 下标、值==========")
list2 = ['dingding', 'dixi', 'lala', 'xiaobo']
for idx, val in enumerate(list2):
    print(f'下标：{idx} 的值为：{val}')
